default : bin/ftdiblaster.ko bin/10-ftdiblaster.rules bin/fbenum.sh

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

bin/ftdiblaster.ko : src/ftdiblaster.c
	echo "obj-m += ftdiblaster.o" > src/Makefile
	-$(MAKE) -C $(KDIR) M=$(PWD)/src modules
	-mv src/ftdiblaster.ko bin/ftdiblaster.ko
	-$(MAKE) -C $(KDIR) V=0 M=$(PWD)/src clean
	rm src/Makefile

bin/10-ftdiblaster.rules : src/10-ftdiblaster.rules
	cp src/10-ftdiblaster.rules bin/10-ftdiblaster.rules

bin/fbenum.sh : src/fbenum.sh
	cp src/fbenum.sh bin/fbenum.sh

clean :
	rm -Rf bin/*

install : bin/ftdiblaster.ko bin/10-ftdiblaster.rules bin/fbenum.sh
	-rmmod ftdi_sio
	-rmmod ftdiblaster
	cp bin/fbenum.sh /usr/bin/fbenum.sh
	cp bin/10-ftdiblaster.rules /etc/udev/rules.d/10-ftdiblaster.rules
	insmod bin/ftdiblaster.ko

